<template>
  <el-button @click="onClick">{{ $t('lang.operate.export') }}</el-button>
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue'
import { exportMethod } from '@/utils/utils'
import { ElMessageBox } from 'element-plus'

export default defineComponent({
  props: {
    updateData: {
      type: Function as PropType<(...args: any) => void>,
      required: true,
    },
  },
  setup(props) {
    const exportData = ref<any>('')
    const ElM = ref<any>('')
    function onClick() {
      exportData.value = props.updateData()
      if (JSON.stringify(exportData.value.data) == '{}') {
        ElM.value = '确定要导出全部数据吗?'
      } else {
        ElM.value = '确定要导出选中的数据吗?'
      }
      ElMessageBox.confirm(ElM.value, '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        if (exportData.value.params) {
          exportData.value.data = {
            ...exportData.value.data,
            ...exportData.value.params,
          }
        }
        exportMethod(exportData.value)
      })
    }
    return {
      exportData,
      ElM,
      onClick,
    }
  },
})
</script>
